package com.ibeetl.admin.aod.service;

import java.util.List;

import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ibeetl.admin.core.util.PlatformException;

import com.ibeetl.admin.aod.dao.AodIndustryKeywordDao;
import com.ibeetl.admin.aod.entity.AodIndustryKeyword;
import com.ibeetl.admin.core.service.BaseService;

/**
 * AodIndustryKeyword Service
 */

@Service
@Transactional
public class AodIndustryKeywordService extends BaseService<AodIndustryKeyword>{

    @Autowired
    protected AodIndustryKeywordDao aodIndustryKeywordDao;

    public PageQuery<AodIndustryKeyword>queryByCondition(PageQuery query){
        PageQuery ret =  aodIndustryKeywordDao.queryByCondition(query);
        queryListAfter(ret.getList());
        return ret;
    }

    public void batchDelAodIndustryKeyword(List<Long> ids){
        try {
            aodIndustryKeywordDao.batchDelAodIndustryKeywordByIds(ids);
        } catch (Exception e) {
            throw new PlatformException("批量删除AodIndustryKeyword失败", e);
        }
    }

    public void saveUnique(AodIndustryKeyword aodIndustryKeyword) {
        AodIndustryKeyword existAodIndustryKeyword = aodIndustryKeywordDao.queryByKeyword(aodIndustryKeyword.getKeyword());
        if (null != existAodIndustryKeyword) {
            throw new PlatformException("关键词已存在");
        }
        this.save(aodIndustryKeyword);
    }

    public void updateUnique(AodIndustryKeyword aodIndustryKeyword) {
        AodIndustryKeyword existAodIndustryKeyword = aodIndustryKeywordDao.queryByKeywordNonId(aodIndustryKeyword);
        if (null != existAodIndustryKeyword) {
            throw new PlatformException("关键词已存在");
        }
        this.update(aodIndustryKeyword);
    }

}